﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/assets/libs/layui/css/layui.css" />
    <link rel="stylesheet" href="/assets/module/admin.css">
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        
    </style>
</head>
<body>
    <!-- 主体部分 -->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 表格工具栏 -->
                <form class="layui-form toolbar searchbar">
                    <div class="layui-form-item">

                        <div class="layui-inline">
                            <label class="layui-form-label">机构名称:</label>
                            <div class="layui-input-inline">
                                <input name="Name" class="layui-input" placeholder="输入" type="text" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">机构类型:</label>
                            <div class="layui-input-inline">
                                <input name="OrganizationType" class="layui-input" placeholder="输入" type="number" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">机构等级:</label>
                            <div class="layui-input-inline">
                                <input name="OrganizationLevel" class="layui-input" placeholder="输入" type="number" />
                            </div>
                        </div>


                        <div class="layui-inline">

                            <button class="layui-btn icon-btn" lay-filter="TbSearch" lay-submit>
                                <i class="layui-icon"></i>搜索
                            </button>
                        </div>
                    </div>
                </form>
                <!-- 数据表格 -->
                <table id="gridTable" lay-filter="gridTable"></table>
            </div>
        </div>
    </div>

    <!-- 表格操作列 -->
    <script type="text/html" id="toolbar">
        <a id="btnAdd" class="layui-btn layui-btn-sm icon-btn" lay-event="add"><i class="layui-icon">&#xe654;</i>新增</a>
        <a id="btnEdit" class="layui-btn layui-btn-warm layui-btn-sm icon-btn" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</a>
        <a id="btnDelete" class="layui-btn layui-btn-danger layui-btn-sm icon-btn" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</a>
    </script>

    <!-- js部分 -->
    <script src="/assets/libs/jquery/jquery-3.2.1.min.js"></script>
    <script src="/assets/libs/layui/layui.js"></script>
    <script src="/assets/js/utils.js"></script>
    <script src="/assets/js/main.js"></script>
    <!--行政区域数据（宿州）-->
    <script src="/assets/module/cascader/citys-data-suzhou.js"></script>
    <script>

        // 全局变量
        var table;

        layui.use(['layer', 'form', 'table', 'util', 'admin', 'setter'], function () {
            var $ = layui.jquery;
            var layer = layui.layer;
            var form = layui.form;
            table = layui.table;
            var util = layui.util;
            var admin = layui.admin;
            var setter = layui.setter;

            // 表格初始化
            layuiTableSet();

            /* 渲染表格 */
            var insTb = table.render({
                elem: '#gridTable',
                url: setter.baseServer + '/OrganizationManage/Organizations/GetPageListJson',
                page: true,
                where: { OrganizationType: 1 },
                toolbar: "#toolbar",
                cols: [[
                    { type: 'checkbox' },
                    { type: 'numbers' },
                    { field: 'Name', title: '机构名称', sort: true },
                    { field: 'Code', title: '机构编码', sort: true },
                    { field: 'LoginName', title: '登录账号', sort: true },
                    //{ field: 'LoginPass', title: '登录密码', sort: true },
                    //{ field: 'BelongArea', title: '所属区域', sort: true },
                    {
                        field: 'Address', title: '地址', templet: function (d) {
                            var t = findAreaStr(citysData, d.BelongArea);
                            return t + " " + d.Address;
                        }
                    },
                    {
                        field: 'OrganizationType', title: '机构类型', sort: true, templet: function (d) {
                            return d.OrganizationType == 0 ? '居家养老' : '机构养老'
                        }
                    },
                    { field: 'OrganizationLevelName', title: '机构等级', sort: true },
                    { field: 'ServiceElderlyCount', title: '服务覆盖老人数', sort: true },

                ]]
            });

            /* 表格搜索 */
            form.on('submit(TbSearch)', function (data) {
                insTb.reload({ where: data.field, page: { curr: 1 } });
                return false;
            });

            /* 表格头工具栏点击事件 */
            table.on('toolbar(gridTable)', function (obj) {
                if (obj.event === 'add') { // 添加
                    showEditModel();
                } else if (obj.event === 'edit') { // 修改
                    var checkRows = table.checkStatus('gridTable');
                    if (checkRows.data.length === 0 || checkRows.data.length > 1) {
                        layer.msg('请选择且只选择一条数据', { icon: 2 });
                        return;
                    }
                    showEditModel(checkRows.data[0]);
                } else if (obj.event === 'del') { // 删除
                    var checkRows = table.checkStatus('gridTable');
                    if (checkRows.data.length === 0) {
                        layer.msg('请选择要删除的数据', { icon: 2 });
                        return;
                    }
                    var ids = checkRows.data.map(function (d) {
                        return d.Id;
                    });
                    doDel({ ids: ids });
                }
            });

            /* 显示表单弹窗 */
            function showEditModel(mData) {
                var id = 0;
                if (mData != undefined && mData != null) { id = mData.Id; }
                admin.open({
                    type: 2,
                    area: ['1024px', '768px'],
                    title: (mData ? '修改' : '添加'),
                    content: 'organizationsElderlyForm.html?id=' + id,
                });
            }

            /* 删除 */
            function doDel(obj) {
                layer.confirm('确定要删除选中数据吗？', {
                    skin: 'layui-layer-admin',
                    shade: .1
                }, function (i) {
                    layer.close(i);
                    var loadIndex = layer.load(2);
                    admin.req('/OrganizationManage/Organizations/DeleteFormJson', obj.ids.join(','), function (res) {
                        layer.close(loadIndex);
                        if (1 === res.Tag) {
                            layer.msg("操作成功", { icon: 1 });
                            insTb.reload({ page: { curr: 1 } });
                        } else {
                            layer.msg(res.Message, { icon: 2 });
                        }
                    }, 'post');
                });
            }

        });
    </script>
</body>
</html>